<?php

namespace app\admin\extend;

trait View
{
	/**
	 * @var \think\View
	 */
	public $view;

	public function assign($name, $value=null) {
		$this->_viewInit();
		$this->view->assign($name, $value);
	}

	public function fetch($vars=[], $template=''): string
	{
		$this->_viewInit();
		return $this->view->fetch($template, $vars);
	}

	private function _viewInit() {
		if(!$this->view) {
			$this->view = new \think\View($this->app);

			$this->_assignInit();
		}
	}

	private function _assignInit() {
		$data = config('business');
		$this->assign($data);
	}
}